<template>
  <div class="dialog-form">
    <el-form ref="refundRef" :model="form" :rules="rules">
      <el-form-item label="来源渠道：">{{ form.channelName }}</el-form-item>
      <el-form-item label="用户编号：">{{ form.platformUserId }}</el-form-item>
      <el-form-item label="电子卡号：">{{ form.cardNo }}</el-form-item>
      <el-form-item label="手机号码：">{{ form.mobile }}</el-form-item>
      <el-form-item label="退款金额：">{{ formatAmount(form.actualFee) }}元</el-form-item>
      <el-form-item label="申请原因：" prop="refundReason">
        <el-input v-model="form.refundReason" type="textarea" :rows="4" placeholder="请输入申请原因，最多200个字" :maxlength="200" />
      </el-form-item>
    </el-form>
    <div class="dialog-footer">
      <el-button @click="onCancel">取消</el-button>
      <el-button type="primary" @click="onConfirm">提交申请</el-button>
    </div>
  </div>
</template>

<script setup>
import { applyOrderRefund } from '@/api/order/refund'
const emits = defineEmits(['cancel', 'confirm'])
const { proxy } = getCurrentInstance()

const refundRef = ref()
const form = ref({})
const rules = {
  refundReason: [
    { required: true, message: "请输入申请原因", trigger: "blur" }
  ],
}

const pageInit = (info) => {
  form.value = info
  form.value.refundReason = ''
}

const onCancel = () => {
  emits('cancel')
}

const onConfirm = () => {
  refundRef.value.validate(valid => {
    if (valid) {
      const params = {
        id: form.value.id,
        refundReason: form.value.refundReason
      }
      applyOrderRefund(params).then(res => {
        proxy.$modal.msgSuccess("申请成功")
        emits('confirm')
      })
    }
  })
}

defineExpose({
  pageInit
})

</script>

<style lang="scss" scoped>

</style>